<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/blog/css/main.css?v=5.1.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="清浮动,css,前端开发," />





  <link rel="alternate" href="/blog/atom.xml" title="东方无双" type="application/atom+xml" />




  <link rel="shortcut icon" type="image/x-icon" href="/blog/favicon.ico?v=5.1.2" />






<meta name="description" content="清浮动下面总结8种清除浮动的方法（测试已通过 ie chrome firefox opera，后面三种方法只做了解就可以了）：  1，父级div定义 heightdemo代码如下：12345678910111213141516171819&amp;lt;html&amp;gt;&amp;lt;body&amp;gt;&amp;lt;style type=&quot;text/css&quot;&amp;gt; .div1&amp;#123;background:#0000">
<meta name="keywords" content="清浮动,css,前端开发">
<meta property="og:type" content="article">
<meta property="og:title" content="2017-09-30-清浮动.md">
<meta property="og:url" content="http://yoursite.com/2017/09/30/2017-09-30-清浮动-md/index.html">
<meta property="og:site_name" content="东方无双">
<meta property="og:description" content="清浮动下面总结8种清除浮动的方法（测试已通过 ie chrome firefox opera，后面三种方法只做了解就可以了）：  1，父级div定义 heightdemo代码如下：12345678910111213141516171819&amp;lt;html&amp;gt;&amp;lt;body&amp;gt;&amp;lt;style type=&quot;text/css&quot;&amp;gt; .div1&amp;#123;background:#0000">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2017-09-29T16:24:37.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="2017-09-30-清浮动.md">
<meta name="twitter:description" content="清浮动下面总结8种清除浮动的方法（测试已通过 ie chrome firefox opera，后面三种方法只做了解就可以了）：  1，父级div定义 heightdemo代码如下：12345678910111213141516171819&amp;lt;html&amp;gt;&amp;lt;body&amp;gt;&amp;lt;style type=&quot;text/css&quot;&amp;gt; .div1&amp;#123;background:#0000">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Pisces',
    version: '5.1.2',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: 'NO8XI81C6V',
      apiKey: '21a1e5defb2c17cc1e9ca4cf22a6dc19',
      indexName: 'chu_jian',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2017/09/30/2017-09-30-清浮动-md/"/>





  <title>2017-09-30-清浮动.md | 东方无双</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">东方无双</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/blog/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/blog/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/blog/2017/09/30/2017-09-30-清浮动-md/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="无双的博客">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="http://upload.jianshu.io/users/upload_avatars/201324/2bc50b2b47b3.jpg?imageMogr2/auto-orient/strip|imageView2/1/w/120/h/120">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="东方无双">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">2017-09-30-清浮动.md</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-09-30T00:23:08+08:00">
                2017-09-30
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/编程/" itemprop="url" rel="index">
                    <span itemprop="name">编程</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="清浮动"><a href="#清浮动" class="headerlink" title="清浮动"></a>清浮动</h1><p>下面总结8种清除浮动的方法（测试已通过 ie chrome firefox opera，后面三种方法只做了解就可以了）： </p>
<h2 id="1，父级div定义-height"><a href="#1，父级div定义-height" class="headerlink" title="1，父级div定义 height"></a>1，父级div定义 height</h2><p>demo代码如下：<br><figure class="highlight html"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div></pre></td><td class="code"><pre><div class="line"></div><div class="line"></div><div class="line"><span class="tag">&lt;<span class="name">html</span>&gt;</span></div><div class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></div><div class="line"><span class="tag">&lt;<span class="name">style</span> <span class="attr">type</span>=<span class="string">"text/css"</span>&gt;</span><span class="undefined"> </span></div><div class="line"><span class="undefined">.div1&#123;background:#000080;border:1px solid red;/*解决代码*/height:200px;&#125; </span></div><div class="line"><span class="undefined">.div2&#123;background:#800080;border:1px solid red;height:100px;margin-top:10px&#125; </span></div><div class="line"><span class="undefined">.left&#123;float:left;width:20%;height:200px;background:#DDD&#125; </span></div><div class="line"><span class="undefined">.right&#123;float:right;width:30%;height:80px;background:#DDD&#125; </span></div><div class="line"><span class="undefined"></span><span class="tag">&lt;/<span class="name">style</span>&gt;</span> </div><div class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"div1"</span>&gt;</span> </div><div class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"left"</span>&gt;</span>Left<span class="tag">&lt;/<span class="name">div</span>&gt;</span> </div><div class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"right"</span>&gt;</span>Right<span class="tag">&lt;/<span class="name">div</span>&gt;</span> </div><div class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span> </div><div class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"div2"</span>&gt;</span> </div><div class="line">div2 </div><div class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span> </div><div class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></div></pre></td></tr></table></figure></p>
<script async src="//jsfiddle.net/matchless5233/7yhp134d/1/embed/html,css,result/"></script>

<p>原理：父级div手动定义height，就解决了父级div无法自动获取到高度的问题。 </p>
<p>优点：简单、代码少、容易掌握 </p>
<p>缺点：只适合高度固定的布局，要给出精确的高度，如果高度和父级div不一样时，会产生问题 </p>
<p>建议：不推荐使用，只建议高度固定的布局时使用 </p>
<h2 id="2，结尾处加空div标签-clear-both"><a href="#2，结尾处加空div标签-clear-both" class="headerlink" title="2，结尾处加空div标签 clear:both"></a>2，结尾处加空div标签 clear:both</h2><p>demo代码如下：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div></pre></td><td class="code"><pre><div class="line"><span class="tag">&lt;<span class="name">style</span> <span class="attr">type</span>=<span class="string">"text/css"</span>&gt;</span><span class="undefined"> </span></div><div class="line"><span class="undefined">.div1&#123;background:#000080;border:1px solid red&#125; </span></div><div class="line"><span class="undefined">.div2&#123;background:#800080;border:1px solid red;height:100px;margin-top:10px&#125; </span></div><div class="line"><span class="undefined">.left&#123;float:left;width:20%;height:200px;background:#DDD&#125; </span></div><div class="line"><span class="undefined">.right&#123;float:right;width:30%;height:80px;background:#DDD&#125; </span></div><div class="line"><span class="undefined">/*清除浮动代码*/ </span></div><div class="line"><span class="undefined">.clearfloat&#123;clear:both&#125; </span></div><div class="line"><span class="undefined"></span><span class="tag">&lt;/<span class="name">style</span>&gt;</span> </div><div class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"div1"</span>&gt;</span> </div><div class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"left"</span>&gt;</span>Left<span class="tag">&lt;/<span class="name">div</span>&gt;</span> </div><div class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"right"</span>&gt;</span>Right<span class="tag">&lt;/<span class="name">div</span>&gt;</span> </div><div class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"clearfloat"</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span> </div><div class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span> </div><div class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"div2"</span>&gt;</span> </div><div class="line">div2 </div><div class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></div></pre></td></tr></table></figure>
<script async src="//jsfiddle.net/matchless5233/h0fLuowz/1/embed/html,result/"></script>

<p>原理：添加一个空div，利用css提高的clear:both清除浮动，让父级div能自动获取到高度 </p>
<p>优点：简单、代码少、浏览器支持好、不容易出现怪问题 </p>
<p>缺点：不少初学者不理解原理；如果页面浮动布局多，就要增加很多空div，让人感觉很不好 </p>
<p>建议：不推荐使用，但此方法是以前主要使用的一种清除浮动方法 </p>
<h2 id="3，父级div定义-伪类-after-和-zoom"><a href="#3，父级div定义-伪类-after-和-zoom" class="headerlink" title="3，父级div定义 伪类:after 和 zoom"></a>3，父级div定义 伪类:after 和 zoom</h2><p>demo代码如下：<br><figure class="highlight html"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div></pre></td><td class="code"><pre><div class="line"><span class="tag">&lt;<span class="name">style</span> <span class="attr">type</span>=<span class="string">"text/css"</span>&gt;</span><span class="undefined"> </span></div><div class="line"><span class="undefined">.div1&#123;background:#000080;border:1px solid red;&#125; </span></div><div class="line"><span class="undefined">.div2&#123;background:#800080;border:1px solid red;height:100px;margin-top:10px&#125; </span></div><div class="line"><span class="undefined">.left&#123;float:left;width:20%;height:200px;background:#DDD&#125; </span></div><div class="line"><span class="undefined">.right&#123;float:right;width:30%;height:80px;background:#DDD&#125; </span></div><div class="line"><span class="undefined">/*清除浮动代码*/ </span></div><div class="line"><span class="undefined">.clearfloat:after&#123;display:block;clear:both;content:"";visibility:hidden;height:0&#125; </span></div><div class="line"><span class="undefined">.clearfloat&#123;zoom:1&#125; </span></div><div class="line"><span class="undefined"></span><span class="tag">&lt;/<span class="name">style</span>&gt;</span> </div><div class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"div1 clearfloat"</span>&gt;</span> </div><div class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"left"</span>&gt;</span>Left<span class="tag">&lt;/<span class="name">div</span>&gt;</span> </div><div class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"right"</span>&gt;</span>Right<span class="tag">&lt;/<span class="name">div</span>&gt;</span> </div><div class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span> </div><div class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"div2"</span>&gt;</span> </div><div class="line">div2 </div><div class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span> </div><div class="line">`</div></pre></td></tr></table></figure></p>
<script async src="//jsfiddle.net/matchless5233/8trdffs2/embed/html,result/"></script>

<p>原理：IE8以上和非IE浏览器才支持:after，原理和方法2有点类似，zoom(IE转有属性)可解决ie6,ie7浮动问题 </p>
<p>优点：浏览器支持好、不容易出现怪问题（目前：大型网站都有使用，如：腾迅，网易，新浪等等） </p>
<p>缺点：代码多、不少初学者不理解原理，要两句代码结合使用才能让主流浏览器都支持。 </p>
<p>建议：推荐使用，建议定义公共类，以减少CSS代码。 </p>
<h2 id="4，父级div定义-overflow-hidden"><a href="#4，父级div定义-overflow-hidden" class="headerlink" title="4，父级div定义 overflow:hidden"></a>4，父级div定义 overflow:hidden</h2><p>demo代码如下：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line"><span class="tag">&lt;<span class="name">style</span> <span class="attr">type</span>=<span class="string">"text/css"</span>&gt;</span><span class="undefined"> </span></div><div class="line"><span class="undefined">.div1&#123;background:#000080;border:1px solid red;/*解决代码*/width:98%;overflow:hidden&#125; </span></div><div class="line"><span class="undefined">.div2&#123;background:#800080;border:1px solid red;height:100px;margin-top:10px;width:98%&#125; </span></div><div class="line"><span class="undefined">.left&#123;float:left;width:20%;height:200px;background:#DDD&#125; </span></div><div class="line"><span class="undefined">.right&#123;float:right;width:30%;height:80px;background:#DDD&#125; </span></div><div class="line"><span class="undefined"></span><span class="tag">&lt;/<span class="name">style</span>&gt;</span> </div><div class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"div1"</span>&gt;</span> </div><div class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"left"</span>&gt;</span>Left<span class="tag">&lt;/<span class="name">div</span>&gt;</span> </div><div class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"right"</span>&gt;</span>Right<span class="tag">&lt;/<span class="name">div</span>&gt;</span> </div><div class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span> </div><div class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"div2"</span>&gt;</span> </div><div class="line">div2 </div><div class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></div></pre></td></tr></table></figure>
<script async src="//jsfiddle.net/matchless5233/cr6ucdco/embed/html,result/"></script>

<p>原理：必须定义width或zoom:1，同时不能定义height，使用overflow:hidden时，浏览器会自动检查浮动区域的高度 </p>
<p>优点：简单、代码少、浏览器支持好 </p>
<p>缺点：不能和position配合使用，因为超出的尺寸的会被隐藏。 </p>
<p>建议：只推荐没有使用position或对overflow:hidden理解比较深的朋友使用。 </p>
<h2 id="5，父级div定义-overflow-auto"><a href="#5，父级div定义-overflow-auto" class="headerlink" title="5，父级div定义 overflow:auto"></a>5，父级div定义 overflow:auto</h2><p>demo代码如下：<br><figure class="highlight html"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line"><span class="tag">&lt;<span class="name">style</span> <span class="attr">type</span>=<span class="string">"text/css"</span>&gt;</span><span class="undefined"> </span></div><div class="line"><span class="undefined">.div1&#123;background:#000080;border:1px solid red;/*解决代码*/width:98%;overflow:auto&#125; </span></div><div class="line"><span class="undefined">.div2&#123;background:#800080;border:1px solid red;height:100px;margin-top:10px;width:98%&#125; </span></div><div class="line"><span class="undefined">.left&#123;float:left;width:20%;height:200px;background:#DDD&#125; </span></div><div class="line"><span class="undefined">.right&#123;float:right;width:30%;height:80px;background:#DDD&#125; </span></div><div class="line"><span class="undefined"></span><span class="tag">&lt;/<span class="name">style</span>&gt;</span> </div><div class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"div1"</span>&gt;</span> </div><div class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"left"</span>&gt;</span>Left<span class="tag">&lt;/<span class="name">div</span>&gt;</span> </div><div class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"right"</span>&gt;</span>Right<span class="tag">&lt;/<span class="name">div</span>&gt;</span> </div><div class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span> </div><div class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"div2"</span>&gt;</span> </div><div class="line">div2 </div><div class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></div></pre></td></tr></table></figure></p>
<script async src="//jsfiddle.net/matchless5233/abfvmj6s/1/embed/html,result/"></script>

<p>原理：必须定义width或zoom:1，同时不能定义height，使用overflow:auto时，浏览器会自动检查浮动区域的高度 </p>
<p>优点：简单、代码少、浏览器支持好 </p>
<p>缺点：内部宽高超过父级div时，会出现滚动条。 </p>
<p>建议：不推荐使用，如果你需要出现滚动条或者确保你的代码不会出现滚动条就使用吧。 </p>
<h2 id="6，父级div-也一起浮动"><a href="#6，父级div-也一起浮动" class="headerlink" title="6，父级div 也一起浮动"></a>6，父级div 也一起浮动</h2><p>demo代码如下：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">&lt;style type=&quot;text/css&quot;&gt; </div><div class="line">.div1&#123;background:#000080;border:1px solid red;/*解决代码*/width:98%;margin-bottom:10px;float:left&#125; </div><div class="line">.div2&#123;background:#800080;border:1px solid red;height:100px;width:98%;/*解决代码*/clear:both&#125; </div><div class="line">.left&#123;float:left;width:20%;height:200px;background:#DDD&#125; </div><div class="line">.right&#123;float:right;width:30%;height:80px;background:#DDD&#125; </div><div class="line">&lt;/style&gt; </div><div class="line">&lt;div class=&quot;div1&quot;&gt; </div><div class="line">&lt;div class=&quot;left&quot;&gt;Left&lt;/div&gt; </div><div class="line">&lt;div class=&quot;right&quot;&gt;Right&lt;/div&gt; </div><div class="line">&lt;/div&gt; </div><div class="line">&lt;div class=&quot;div2&quot;&gt; </div><div class="line">div2 </div><div class="line">&lt;/div&gt;</div></pre></td></tr></table></figure></p>
<script async src="//jsfiddle.net/matchless5233/yofddvvk/embed/html,result/"></script>

<p>原理：所有代码一起浮动，就变成了一个整体 </p>
<p>优点：没有优点 </p>
<p>缺点：会产生新的浮动问题。 </p>
<p>建议：不推荐使用，只作了解。 </p>
<h2 id="7，父级div定义-display-table"><a href="#7，父级div定义-display-table" class="headerlink" title="7，父级div定义 display:table"></a>7，父级div定义 display:table</h2><p>demo代码如下：<br><figure class="highlight html"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line"><span class="tag">&lt;<span class="name">style</span> <span class="attr">type</span>=<span class="string">"text/css"</span>&gt;</span><span class="undefined"> </span></div><div class="line"><span class="undefined">.div1&#123;background:#000080;border:1px solid red;/*解决代码*/width:98%;display:table;margin-bottom:10px;&#125; </span></div><div class="line"><span class="undefined">.div2&#123;background:#800080;border:1px solid red;height:100px;width:98%;&#125; </span></div><div class="line"><span class="undefined">.left&#123;float:left;width:20%;height:200px;background:#DDD&#125; </span></div><div class="line"><span class="undefined">.right&#123;float:right;width:30%;height:80px;background:#DDD&#125; </span></div><div class="line"><span class="undefined"></span><span class="tag">&lt;/<span class="name">style</span>&gt;</span> </div><div class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"div1"</span>&gt;</span> </div><div class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"left"</span>&gt;</span>Left<span class="tag">&lt;/<span class="name">div</span>&gt;</span> </div><div class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"right"</span>&gt;</span>Right<span class="tag">&lt;/<span class="name">div</span>&gt;</span> </div><div class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span> </div><div class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"div2"</span>&gt;</span> </div><div class="line">div2 </div><div class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></div></pre></td></tr></table></figure></p>
<script async src="//jsfiddle.net/matchless5233/63cv9bb9/embed/html,result/"></script>

<p>原理：将div属性变成表格 </p>
<p>优点：没有优点 </p>
<p>缺点：会产生新的未知问题。 </p>
<p>建议：不推荐使用，只作了解。 </p>
<h2 id="8，结尾处加-br标签-clear-both"><a href="#8，结尾处加-br标签-clear-both" class="headerlink" title="8，结尾处加 br标签 clear:both"></a>8，结尾处加 br标签 clear:both</h2><figure class="highlight html"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line"><span class="tag">&lt;<span class="name">style</span> <span class="attr">type</span>=<span class="string">"text/css"</span>&gt;</span><span class="undefined"> </span></div><div class="line"><span class="undefined">.div1&#123;background:#000080;border:1px solid red;margin-bottom:10px;zoom:1&#125; </span></div><div class="line"><span class="undefined">.div2&#123;background:#800080;border:1px solid red;height:100px&#125; </span></div><div class="line"><span class="undefined">.left&#123;float:left;width:20%;height:200px;background:#DDD&#125; </span></div><div class="line"><span class="undefined">.right&#123;float:right;width:30%;height:80px;background:#DDD&#125; </span></div><div class="line"><span class="undefined">.clearfloat&#123;clear:both&#125; </span></div><div class="line"><span class="undefined"></span><span class="tag">&lt;/<span class="name">style</span>&gt;</span> </div><div class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"div1"</span>&gt;</span> </div><div class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"left"</span>&gt;</span>Left<span class="tag">&lt;/<span class="name">div</span>&gt;</span> </div><div class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"right"</span>&gt;</span>Right<span class="tag">&lt;/<span class="name">div</span>&gt;</span> </div><div class="line"><span class="tag">&lt;<span class="name">br</span> <span class="attr">class</span>=<span class="string">"clearfloat"</span> /&gt;</span> </div><div class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span> </div><div class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"div2"</span>&gt;</span> </div><div class="line">div2 </div><div class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></div></pre></td></tr></table></figure>
<script async src="//jsfiddle.net/matchless5233/h9o8sgbz/embed/html,result/"></script>

<p>原理：父级div定义zoom:1来解决IE浮动问题，结尾处加 br标签 clear:both </p>
<p>建议：不推荐使用，只作了解。</p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/blog/tags/清浮动/" rel="tag"># 清浮动</a>
          
            <a href="/blog/tags/css/" rel="tag"># css</a>
          
            <a href="/blog/tags/前端开发/" rel="tag"># 前端开发</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blog/2017/09/29/hello-world/" rel="next" title="Hello World">
                <i class="fa fa-chevron-left"></i> Hello World
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/2017/09/30/vue开发环境跨域处理/" rel="prev" title="vue开发环境跨域处理">
                vue开发环境跨域处理 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <div id="lv-container" data-id="city" data-uid="MTAyMC8zMTEyMS83Njcw"></div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          
            <img class="site-author-image" itemprop="image"
              src="http://upload.jianshu.io/users/upload_avatars/201324/2bc50b2b47b3.jpg?imageMogr2/auto-orient/strip|imageView2/1/w/120/h/120"
              alt="无双的博客" />
          
            <p class="site-author-name" itemprop="name">无双的博客</p>
            <p class="site-description motion-element" itemprop="description"></p>
        </div>

        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
            
              <a href="/blog/archives/">
            
                <span class="site-state-item-count">8</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/blog/categories/index.html">
                <span class="site-state-item-count">3</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/blog/tags/index.html">
                <span class="site-state-item-count">13</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        
          <div class="feed-link motion-element">
            <a href="/blog/atom.xml" rel="alternate">
              <i class="fa fa-rss"></i>
              RSS
            </a>
          </div>
        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/DongFangWuShuang" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>GitHub</a>
              </span>
            
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="https://gitee.com/chu_jian/" title="Gitee" target="_blank">Gitee</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://github.com/DongFangWuShuang/" title="Github" target="_blank">Github</a>
                </li>
              
            </ul>
          </div>
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#清浮动"><span class="nav-number">1.</span> <span class="nav-text">清浮动</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1，父级div定义-height"><span class="nav-number">1.1.</span> <span class="nav-text">1，父级div定义 height</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2，结尾处加空div标签-clear-both"><span class="nav-number">1.2.</span> <span class="nav-text">2，结尾处加空div标签 clear:both</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3，父级div定义-伪类-after-和-zoom"><span class="nav-number">1.3.</span> <span class="nav-text">3，父级div定义 伪类:after 和 zoom</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4，父级div定义-overflow-hidden"><span class="nav-number">1.4.</span> <span class="nav-text">4，父级div定义 overflow:hidden</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5，父级div定义-overflow-auto"><span class="nav-number">1.5.</span> <span class="nav-text">5，父级div定义 overflow:auto</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6，父级div-也一起浮动"><span class="nav-number">1.6.</span> <span class="nav-text">6，父级div 也一起浮动</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#7，父级div定义-display-table"><span class="nav-number">1.7.</span> <span class="nav-text">7，父级div定义 display:table</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#8，结尾处加-br标签-clear-both"><span class="nav-number">1.8.</span> <span class="nav-text">8，结尾处加 br标签 clear:both</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2015 &mdash; <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">无双的博客</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.2</div>




        




  <script type="text/javascript">
    (function() {
      var hm = document.createElement("script");
      hm.src = "//tajs.qq.com/stats?sId=63778783";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.2"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.2"></script>



  
  


  <script type="text/javascript" src="/blog/js/src/affix.js?v=5.1.2"></script>

  <script type="text/javascript" src="/blog/js/src/schemes/pisces.js?v=5.1.2"></script>



  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=5.1.2"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=5.1.2"></script>


  

  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.2"></script>



  


  




	





  





  
    <script type="text/javascript">
      (function(d, s) {
        var j, e = d.getElementsByTagName(s)[0];
        if (typeof LivereTower === 'function') { return; }
        j = d.createElement(s);
        j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
        j.async = true;
        e.parentNode.insertBefore(j, e);
      })(document, 'script');
    </script>
  








  





  

  

  

  

  

  

</body>
</html>
